﻿using System;

namespace IupNET
{
    public class Dialog:Control
    {

        public Dialog()
            : base(IntPtr.Zero)
        {

        }

        public Dialog(Control child) : base(Iupc.Dialog(child))
        {
            
        }

        public void Create(Control child)
        {
            //helper function to create from class constructor

            if (cobject != IntPtr.Zero)
                throw new Exception("Dialog can not be Create():d when it already has a child control");
            Initialize(Iupc.Dialog(child));
        }

        public Color Background
        {
            get
            {
                return Convert.StringToColor(GetAttribute("BACKGROUND"));
            }
            set
            {
                SetAttribute("BACKGROUND", Convert.ColorToString(value));
            }
        }


        public Image BackgroundImage
        {
            
            set
            {
                SetAttribute("BACKGROUND", value.HandleName);
            }

            get
            {
                return GetHandle(GetAttribute("BACKGROUND")) as Image;
            
            }
        }

        public bool Border
        {
            get
            {
                return GetAttribute("BORDER") == "YES";
            }
            set
            {
                SetAttribute("BORDER", value ? "YES" : "NO");
            }
        }


        public Cursor Cursor
        {
            get
            {
                return Convert.StringToCursor(GetAttribute("CURSOR"));
            }
            set
            {
                SetAttribute("CURSOR", Convert.CursorToString(value));
            }
        }

        public bool DragDrop
        {
            get
            {
                return GetAttribute("DRAGDROP") == "YES";
            }
            set
            {
                SetAttribute("DRAGDROP", value ? "YES" : "NO");
            }
        }

        public virtual void Show()
        {
            if (Iupc.Show(this) != 0)
                throw new Exception("Something was wrong when the Dialog was Show():n");
        }

        public virtual void ShowXY(int x, int y)
        {
            if(Iupc.ShowXY(cobject, x, y)!=0)
                throw new Exception("Something was wrong when the Dialog was ShowXY():n");
        }

        public virtual void Popup(int x, int y)
        {
            if (Iupc.Popup(cobject, x, y) != 0)
                throw new Exception("Something was wrong when the Dialog was Popup():ed");
        }


        public Button DefaultEnter
        {
            get
            {
                return GetHandle(GetAttribute("DEFAULTENTER")) as Button;
            }

            set
            {
                SetAttribute("DEFAULTENTER", value.HandleName);
            }
        }

        public Button DefaultEsc
        {
            get
            {
                return GetHandle(GetAttribute("DEFAULTESC")) as Button;
            }

            set
            {
                SetAttribute("DEFAULTESC", value.HandleName);
            }
        }

        public bool DialogFrame
        {
            get
            {
                return GetAttribute("DIALOGFRAME") == "YES";
            }
            set
            {
                SetAttribute("DIALOGFRAME", value ? "YES" : "NO");
            }
        }

        public Image Icon
        {
            set
            {
                SetAttribute("ICON", value.HandleName);
            }

            get
            {
                return GetHandle(GetAttribute("ICON")) as Image;

            }
        }

        /// <summary>
        /// Makes the dialog occupy the whole screen over any system bars in the main monitor. 
        /// All dialog details, such as title bar, borders, maximize button, etc, are removed. 
        /// In Motif you may have to click in the dialog to set its focus.
        /// In Motif if set to true when the dialog is hidden, then it can not be changed after it is visible.
        /// </summary>
        public bool Fullscreen
        {
            get
            {
                return GetAttribute("FULLSCREEN") == "YES";
            }
            set
            {
                SetAttribute("FULLSCREEN", value ? "YES" : "NO");
            }
        }

        public IntPtr HWND
        {
            get
            {
                return Iupc.GetAttributePtr(cobject, "HWND");
            }
        }

        public bool MaxBox
        {
            get
            {
                return GetAttribute("MAXBOX") == "YES";
            }
            set
            {
                SetAttribute("MAXBOX", value ? "YES" : "NO");
            }
        }

        public Size2i MaxSize
        {
            get
            {
                return Convert.StringToSize(GetAttribute("MAXSIZE"));
            }
            set
            {
                SetAttribute("MAXSIZE", Convert.SizeToString(value));
            }
        }



        public Menu Menu
        {
            get
            {
                return GetHandle(GetAttribute("MENU")) as Menu;
            }

            set
            {
                SetAttribute("MENU", value.HandleName);
            }
        }


        public bool MinBox
        {
            get
            {
                return GetAttribute("MINBOX") == "YES";
            }
            set
            {
                SetAttribute("MINBOX", value ? "YES" : "NO");
            }
        }

        public Size2i MinSize
        {
            get
            {
                return Convert.StringToSize(GetAttribute("MINSIZE"));
            }
            set
            {
                SetAttribute("MINSIZE", Convert.SizeToString(value));
            }
        }

        public bool Modal
        {
            get
            {
                return GetAttribute("MODAL") == "YES";
            }
        }


        public IntPtr NativeParent
        {
            get
            {
                return Iupc.GetAttributePtr(cobject, "NATIVEPARENT");
            }
            set
            {
                Iupc.SetAttributePtr(cobject, "NATIVEPARENT", value);
            }
        }

        public Dialog ParentDialog
        {
            get
            {
                return GetHandle(GetAttribute("PARENTDIALOG")) as Dialog;
            }

            set
            {
                SetAttribute("PARENTDIALOG", value.HandleName);
            }
        }



        public Placement Placement
        {
            get
            {
                return Convert.StringToPlacement(GetAttribute("PLACEMENT"));
            }

            set
            {
                SetAttribute("PLACEMENT", Convert.PlacementToString(value));
            }
        }

        public bool Resize
        {
            get
            {
                return GetAttribute("RESIZE") == "YES";
            }
            set
            {
                SetAttribute("RESIZE", value ? "YES" : "NO");
            }
        }


        public bool Shrink
        {
            get
            {
                return GetAttribute("SHRINK") == "YES";
            }
            set
            {
                SetAttribute("SHRINK", value ? "YES" : "NO");
            }
        }

        public Control StartFocus
        {
            get
            {
                return GetHandle(GetAttribute("STARTFOCUS")) as Control;
            }

            set
            {
                SetAttribute("STARTFOCUS", value.HandleName);
            }
        }

        public IntPtr XWindow
        {
            get
            {
                return Iupc.GetAttributePtr(cobject, "XWINDOW");
            }
        }


        public bool HideTaskbar
        {
           
            set
            {
                SetAttribute("HIDETASKBAR", value ? "YES" : "NO");
            }
        }

        public bool Topmost
        {
            get
            {
                return GetAttribute("TOPMOST") == "YES";
            }
            set
            {
                SetAttribute("TOPMOST", value ? "YES" : "NO");
            }
        }


        public bool Tray
        {
            get
            {
                return GetAttribute("TRAY") == "YES";
            }
            set
            {
                SetAttribute("TRAY", value ? "YES" : "NO");
            }
        }

        public Image TrayImage
        {
            set
            {
                string n = value.HandleName;
                if (n == null)
                    return;
                SetAttribute("TRAYIMAGE", n);
            }

        }

        public string TrayTip
        {
            get
            {
                return GetAttribute("TRAYTIP");
            }
            set
            {
                SetAttribute("TRAYTIP", value);
            }
        }

        public bool Toolbox
        {
            get
            {
                return GetAttribute("TOOLBOX") == "YES";
            }
            set
            {
                SetAttribute("TOOLBOX", value ? "YES" : "NO");
                
            }
        }

        public void BringFront()
        {
            SetAttribute("BRINGFRONT", "YES");
        }


        public bool Composited
        {
            get
            {
                return GetAttribute("COMPOSITED") == "YES";
            }
            set
            {
                SetAttribute("COMPOSITED", value ? "YES" : "NO");

            }
        }


        public bool Control
        {
            get
            {
                return GetAttribute("CONTROL") == "YES";
            }
            set
            {
                SetAttribute("CONTROL", value ? "YES" : "NO");

            }
        }

        public bool HelpButton
        {
            get
            {
                return GetAttribute("HELPBUTTON") == "YES";
            }
            set
            {
                SetAttribute("HELPBUTTON", value ? "YES" : "NO");

            }
        }

        public bool Layered
        {
            get
            {
                return GetAttribute("LAYERED") == "YES";
            }
            set
            {
                SetAttribute("LAYERED", value ? "YES" : "NO");

            }
        }

        public int LayerAlpha
        {
            get
            {
                return Convert.StringToInt(GetAttribute("LAYERALPHA"));
            }
            set
            {
                SetAttribute("LAYERALPHA", value.ToString());
            }
        }

        public EventCallback CloseCB
        {
            get
            {
                return CBHandler.Fetch("CLOSE_CB");
            }
            set
            {
                CBHandler.Set("CLOSE_CB", value);
            }
        }

        public EventCallback DropFilesCB
        {
            get
            {
                return CBHandler.Fetch("DROPFILES_CB");
            }
            set
            {
                CBHandler.Set("DROPFILES_CB", value);
            }
        }

        public EventCallback ResizeCB
        {
            get
            {
                return CBHandler.Fetch("RESIZE_CB");
            }
            set
            {
                CBHandler.Set("RESIZE_CB", value);
            }
        }

        public EventCallback ShowCB
        {
            get
            {
                return CBHandler.Fetch("SHOW_CB");
            }
            set
            {
                CBHandler.Set("SHOW_CB", value);
            }
        }

        public EventCallback TrayClickCB
        {
            get
            {
                return CBHandler.Fetch("TRAYCLICK_CB");
            }
            set
            {
                CBHandler.Set("TRAYCLICK_CB", value);
            }
        }
        
        //TODO: mdi stuff for windows (booth actions and attributes)

    }
}
